<!--#include file="classData.asp"-->
<!--#include file="classSort.asp"-->
<%
Response.Buffer = True 
Response.ExpiresAbsolute = Now() - 1 
Response.Expires = 0 
Response.CacheControl = "no-cache" 
Response.AddHeader "Pragma", "No-Cache"


	UserId = 1
	ManagerId = Request.Form("ManagerId")
	SeasonNum = Request.Form("SeasonNum")
	AreaLevel = Request.Form("AreaLevel")
	purl = Request.Form("purl")
	cState = Request.Form("cState")
	

	set HuaObj = new sysData
	HuaObj.sqlConnOpen()



	set LockRds=server.CreateObject("ADODB.recordset")
	HuaObj.DbQuery LockRds,"sysLeagueLock",QueryStr,0," 1=1"
	
	tNum = LockRds.RecordCount
		
	LockRds.Close

	If tNum = 0 Then
	
	InsertSql = "INSERT INTO sysLeagueLock VALUES("&UserId&",getdate())"
	HuaObj.SCommand(InsertSql)
	
	End If

	set LockRdsB=server.CreateObject("ADODB.recordset")
	HuaObj.DbQuery LockRdsB,"sysLeagueLock",QueryStr,0," 1=1 ORDER BY OpDate DESC"
	
	tmid = LockRdsB("ManagerId")
		
	LockRdsB.Close

	If tmid = UserId Then

	HuaObj.p_DbConnection.BeginTrans
	on error resume next


	'更新主场
	InsertSql = "UPDATE a SET a.Score = b.Score,a.Goal = b.Goal,a.Fumble = b.Fumble,a.GoalDif = b.GoalDif,a.TotalRound = b.RealRound,a.WinNum = b.WinNum,a.LostNum = b.LostNum,a.DrawNum = b.DrawNum FROM AreaLeague AS a,CheckLB AS b WHERE a.SeasonNum = b.SeasonNum AND a.AreaLevel = b.AreaLevel AND a.ManagerId = b.ManagerId AND b.ManagerId = "&ManagerId
	HuaObj.SCommand(InsertSql)
	
	InsertSql = "DELETE FROM CheckLB WHERE ManagerId = "&ManagerId
	HuaObj.SCommand(InsertSql)

	InsertSql = "DELETE FROM sysLeagueLock"
	HuaObj.SCommand(InsertSql)



	if err.number =0 then  
    	HuaObj.p_DbConnection.CommitTrans  '如果没有conn错误，则执行事务提交
		call SortSameScore(SeasonNum,1,AreaLevel,ManagerId)
		call SortScore(SeasonNum,1,AreaLevel)
		Response.Redirect(purl&"1")
	else 
    	HuaObj.p_DbConnection.RollbackTrans '否则回滚
    	strerr=err.Description
    	Response.Write "数据库错误！错误日志：<font color=red>"&strerr &"</font>"
    	Response.End 
	end if

	Else
	
		InsertSql = "DELETE FROM sysLeagueLock WHERE OpDate < DATEADD(n,-3,'"&Date&" "&Time&"')"
		HuaObj.SCommand(InsertSql)
		Response.Write("<script>alert(""报分系统忙，请稍候报分！"")</script>")
		Response.Redirect(purl&"1")

	End If
	
	HuaObj.sqlConnClose()


%>
